package com.wc.算法基础课.B第二讲数据结构.栈.表达式求值;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/4/30 18:03
 * @description https://www.acwing.com/problem/content/3305/
 */
public class Main {
    /**
     * 中缀表达式计算
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static char[] s = new char[1];
    static Stack<Integer> num = new Stack<>();
    static Stack<Character> op = new Stack<>();
    static Map<Character, Integer> pr = new HashMap<>();

    public static void main(String[] args) {
        s = sc.next().toCharArray();
        pr.put('+', 1);
        pr.put('-', 1);
        pr.put('*', 2);
        pr.put('/', 2);
        pr.put('(', 0);
        for (int i = 0; i < s.length; i++) {
            if (Character.isDigit(s[i])) {
                int j = i;
                int x = 0;
                while (j < s.length && Character.isDigit(s[j])) {
                    x = x * 10 + s[j] - '0';
                    j++;
                }
                i = j - 1;
                num.push(x);
            } else if (s[i] == '(') op.add(s[i]);
            else if (s[i] == ')') {
                while (op.peek() != '(') eval();
                // 将左括号去掉
                op.pop();
            } else {
                while (op.size() > 0 && pr.get(op.peek()) >= pr.get(s[i])) eval();
                op.push(s[i]);
            }
        }
        while (!op.isEmpty()) eval();
        out.println(num.peek());
        out.flush();
    }

    static void eval() {
        int b = num.pop(), a = num.pop();
        int x;
        if (op.peek() == '+') x = a + b;
        else if (op.peek() == '-') x = a - b;
        else if (op.peek() == '/') x = a / b;
        else x = a * b;
        num.push(x);
        op.pop();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
